﻿using MvcApplication2.DataAccess;
using MvcApplication2.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication2.Bussiness
{
    public class EmployeeBusinessLayer
    {
        public List<Employee> GetEmployee()
        {
            List<Employee> employees = new List<Employee>();
            SalesERPDAL salesDal = new SalesERPDAL();
            return salesDal.Employees.ToList();
        }
        public Employee SaveEmployee(Employee e)
        {
            SalesERPDAL sale = new SalesERPDAL();
            sale.Employees.Add(e);
            sale.SaveChanges();
            return e;
        }
        public bool DeleteEmployee(string empID)
        {
            bool flag = false;
            SalesERPDAL sale = new SalesERPDAL();
            int emp = Convert.ToInt32(empID);
             Employee e= sale.Employees.FirstOrDefault(item => item.EmployeeID == emp);
            sale.Employees.Remove(e);
            int i = sale.SaveChanges();
            if (i > 0)
            {
                flag = true;
            }
            return flag;
        }
        public bool IsValidUser(UserDetails u)
        {
            bool flag = false;
            if (u.UserName == "Admin" && u.PassWord == "Admin")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public UserStatus GetUserValidity(UserDetails u)
        {
                if (u.UserName == "Admin" && u.PassWord == "Admin")
                {
                  return UserStatus.AuthenticatedAdmin;
             }
                else if (u.UserName == "Sukesh" && u.PassWord == "Sukesh")
             {
                 return UserStatus.AuthentucatedUser;
            }
            else
            {
               return UserStatus.NonAuthenticatedUser;
            }
        }
        public void UploadEmployee(List<Employee> list)
        {
            SalesERPDAL sales = new SalesERPDAL();
            sales.Employees.AddRange(list);
            sales.SaveChanges();
 
        }
    }
}